package com.anrongtec.zcpt.ui.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.anrongtec.zcpt.ApiConfig;
import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 修改密码页
 */
public class AmendPasswordActivity extends BaseActivity {

    @BindView(R.id.et_original_password)
    EditText etOriginalPassword;//原密码
    @BindView(R.id.iv_delete_original_password)
    ImageView ivDeleteOriginalPassword;//原密码删除图标
    @BindView(R.id.et_new_password)
    EditText etNewPassword;//新密码
    @BindView(R.id.iv_delete_new_password)
    ImageView ivDeleteNewPassword;//新密码删除图标
    @BindView(R.id.et_affirm_login_password)
    EditText etAffirmLoginPassword;//确认登录密码
    @BindView(R.id.iv_delete_verify_password)
    ImageView ivDeleteVerifyPassword;//删除确定密码图标
    @BindView(R.id.btn_amend_password)
    Button btnAmendPassword;//确定修改密码



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleShow(false);
        setContentView(R.layout.activity_amend_password);
        ButterKnife.bind(this);
        initTopBar(this,true,"修改密码","");
        etOriginalPassword.addTextChangedListener(mTextWatcher);
        etNewPassword.addTextChangedListener(mTextWatcher);
        etAffirmLoginPassword.addTextChangedListener(mTextWatcher);
    }

    @OnClick({R.id.iv_delete_original_password, R.id.iv_delete_new_password, R.id.iv_delete_verify_password,R.id.btn_amend_password})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_delete_original_password://原密码删除图标
                etOriginalPassword.setText("");
                ivDeleteOriginalPassword.setVisibility(View.GONE);
                break;
            case R.id.iv_delete_new_password://新密码删除图标
                etNewPassword.setText("");
                ivDeleteNewPassword.setVisibility(View.GONE);
                break;
            case R.id.iv_delete_verify_password://删除确定密码图标
                etAffirmLoginPassword.setText("");
                ivDeleteVerifyPassword.setVisibility(View.GONE);
                break;
            case R.id.btn_amend_password://确定修改密码
                showToastCustom("修改成功", ApiConfig.SUCCESS);
                finish();
                break;

        }
    }

    private TextWatcher mTextWatcher = new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
        @Override
        public void afterTextChanged(Editable s) {
            if (etOriginalPassword.getText().length()!= 0) {
                ivDeleteOriginalPassword.setVisibility(View.VISIBLE);
            } else {
                ivDeleteOriginalPassword.setVisibility(View.GONE);
            }

            if (etNewPassword.getText().length()!= 0) {
                ivDeleteNewPassword.setVisibility(View.VISIBLE);
            } else {
                ivDeleteNewPassword.setVisibility(View.GONE);
            }

            if (etAffirmLoginPassword.getText().length() != 0) {
                ivDeleteVerifyPassword.setVisibility(View.VISIBLE);
            } else {
                ivDeleteVerifyPassword.setVisibility(View.GONE);
            }


            if (etOriginalPassword.getText().length()!= 0 &&
                    etNewPassword.getText().length() != 0&&
                    etAffirmLoginPassword.getText().length() != 0) {

                btnAmendPassword.setEnabled(true);
            } else {

                btnAmendPassword.setEnabled(false);
            }
        }
    };
}
